<div class="eavFields form">
<?php echo $form->create($fieldModelAlias, array('url'=>'/'.$this->params['url']['url'],'id'=>"UserFieldEditorForm"));?>
	<?php
		echo $form->inputs(null,null,'add');
	?>
		<!-- <a href="javascript:void();" onclick="return insertRange();">Insert numeric range</a>	 -->
<?php echo $form->end(__('Submit'));?>
</div>
<div class="actions">
	<ul>
		<li><?php echo $html->link(__('List EavFields', true), array('action'=>'index'));?></li>
	</ul>
</div>
<?php echo $javascript->link('/eav/js/eav.js',false)?>

<script type="text/javascript">
	var typeOptions =  <?php echo $javascript->object(ClassRegistry::getObject($fieldModelAlias)->getOptionsFieldType())?>;
	Eav.modelAlias = "<?php echo $fieldModelAlias?>";
	$(document).ready(function()
	{
			Eav.doForFieldType_old = Eav.doForFieldType;
			Eav.checkfForUrlMaksing = function()
			{
				if($('#'+this.getFieldId('Type')).val() == "url")
				{
					$('#UserFieldMaskUrl').parent().show();
					$('#UserFieldAnchorText').parent().show();
				}else
				{
					$('#UserFieldMaskUrl').parent().hide();
					$('#UserFieldAnchorText').parent().hide();
				}
			}
			Eav.doForFieldType = function()
			{
    			this.doForFieldType_old();
    			this.checkfForUrlMaksing();
			}
			Eav.typeWithOptions = $.makeArray(typeOptions);
			$('#'+Eav.getFieldId('Type')).change(function(){
				Eav.doForFieldType();
			});
			var html = $('#UserFieldMaskUrl').parent().outerHTML();
			var anchorHtml = $('#UserFieldAnchorText').parent().outerHTML();
			$('#UserFieldMaskUrl').parent().remove();
			$('#UserFieldAnchorText').parent().remove();
			$('#'+Eav.getFieldId('Type')).parent().after(html).after(anchorHtml);
			Eav.doForFieldType();
	});
</script>
<script type="text/javascript">
$(document).ready(function(){

	$("#UserFieldEditorForm").submit(checkRequiredField);
		
})
function checkRequiredField(obj)
{
	var alertMessage = "<?php echo __("You can set this field as required only if both 'show on register' and 'show on edit profile' properties are checked.");?>";
	if($('#UserFieldRequired').val() == 1 && ($('#UserFieldRegister').attr('checked') == false || $('#UserFieldEdit').attr('checked') == false))
	{
		alert(alertMessage);
		return false;
	}
	return true;
}
</script>